// RHHardwareSPI.h
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2011 Mike McCauley
// Contributed by Joanna Rutkowska
// $Id: RHHardwareSPI.h,v 1.12 2020/01/05 07:02:23 mikem Exp $

#ifndef RHHardwareSPI_h
#define RHHardwareSPI_h

#include "RHGenericSPI.h"

class RHHardwareSPI : public RHGenericSPI
{
#ifdef RH_HAVE_HARDWARE_SPI
public:
  RHHardwareSPI (Frequency frequency = Frequency4MHz, BitOrder bitOrder = BitOrderMSBFirst,
		 DataMode dataMode = DataMode0);
  uint8_t transfer (uint8_t data);

#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
  uint8_t transfer2B(uint8_t byte0, uint8_t byte1);
  uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
  uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);
#endif

  void attachInterrupt();
  void detachInterrupt();
  void begin();
  void end();
#else
  uint8_t transfer(uint8_t /*data*/) {return 0;}
  void begin(){}
  void end(){}

#endif

  virtual void beginTransaction();
  virtual void endTransaction();
  virtual void usingInterrupt(uint8_t interruptNumber);

protected:

#if defined(SPI_HAS_TRANSACTION)
  SPISettings  _settings;
#endif
};

extern RHHardwareSPI hardware_spi;

#endif
